﻿Imports Microsoft.Win32
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Public Class TFSServer
  Private Const VisualStudio2008Key As String = "Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers"

  Private Sub New()

  End Sub

  Shared Function Servers() As List(Of String)

    Dim serverlist = New List(Of String)

    Using serversKey = Registry.CurrentUser.OpenSubKey(VisualStudio2008Key)
      If serversKey IsNot Nothing Then
        For Each valueName In serversKey.GetValueNames
          serverlist.Add(valueName)
        Next
      End If
    End Using

    Return serverlist

  End Function


  Public Shared Function Projects(ByVal TFSServerName As String) As List(Of String)
    Dim projectlist As New List(Of String)

    Dim tfsServer As TeamFoundationServer = TeamFoundationServerFactory.GetServer(TFSServerName)
    tfsServer.Authenticate()

    Dim wits As WorkItemStore = New WorkItemStore(TFSServerName)
    For Each p As Project In wits.Projects

      projectlist.Add(p.Name)

    Next

    Return projectlist

  End Function
End Class
